package com.tanhua.server.controller;

import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.RecommendUserDto;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 首页今日佳人
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询推荐用户分页列表
     *    get  recommendation?page=1&size=10
     *    请求参数
     *      query ： RecommendUserDto
     *    相应数据：
     *      ResponseEntity <PageResult>
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto) {
        //调用service查询
        PageResult result = tanhuaService.recommendation(dto);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询佳人信息
     *      /:id/personalInfo
     */
    @GetMapping("/{userId}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("userId") Long userId) {
        TodayBest vo = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询陌生人问题
     *   GET   /strangerQuestions？userId=123
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String content =  tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(content);
    }

    /**
     * 回复陌生人问题
     *     POST   /strangerQuestions
     *     参数：
     *       body：
     *          userId,reply
     */
    @PostMapping("/strangerQuestions")
    public  ResponseEntity strangerQuestions(@RequestBody Map map) {
        //提取参数
        String reply = (String) map.get("reply");
        String str = map.get("userId").toString();
        Long userId = Long.valueOf(str);
        //调用service发送
        tanhuaService.replay(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     *   GET   /search
     *   请求参数  gender，distance
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,String distance) {
        List<NearUserVo> vos = tanhuaService.search(gender,distance);
        return ResponseEntity.ok(vos);
    }
}
